package com.test.controller;

import com.test.entity.User;
import com.test.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 用户登录方法
     *
     * @return
     */
    @PostMapping("login")
    public String login(User user, HttpSession session) {
        User userDb = userService.login(user);
        if (userDb != null) {
            session.setAttribute("user", userDb);
            return "redirect:/file/showAll";
        } else {
            return "login";
        }
    }
}
